package com.koo.modules.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koo.common.utils.MyStrUtil;
import com.koo.common.utils.PageUtils;
import com.koo.common.utils.Query;
import com.koo.modules.base.dao.BaseStoreInfoDao;
import com.koo.modules.base.entity.BaseStoreInfoEntity;
import com.koo.modules.base.service.BaseStoreInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

@Slf4j
@Service
public class BaseStoreInfoServiceImpl extends ServiceImpl<BaseStoreInfoDao, BaseStoreInfoEntity> implements BaseStoreInfoService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Object key = params.get("key");
        LambdaQueryWrapper<BaseStoreInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(MyStrUtil.isNotEmpty(key), BaseStoreInfoEntity::getMobile, key)
                .or().eq(MyStrUtil.isNotEmpty(key), BaseStoreInfoEntity::getCardNo, key);

        IPage<BaseStoreInfoEntity> page = this.page(
                new Query<BaseStoreInfoEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}